package com.example.zhyq.visit

import androidx.lifecycle.MutableLiveData
import com.example.base.entity.VisitBean
import com.example.base.entity.VisitBeanItem
import com.example.base.mvvm.BaseViewModel
import com.example.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VisitViewModel @Inject constructor(val apiService: ApiService): BaseViewModel() {

    val getVisit = MutableLiveData<VisitBean>()

    val getVisitById = MutableLiveData<VisitBeanItem>()

    val approveVisit = MutableLiveData<VisitBeanItem>()

    val rejectVisit = MutableLiveData<VisitBeanItem>()

    val deleteVisit = MutableLiveData<Boolean>()

    val addVisit = MutableLiveData<VisitBeanItem>()

    fun getVisit() {
        httpRequest({apiService.getVisit()},{getVisit.postValue(it)})
    }

    fun getVisitByStatus(status:String) {
        httpRequest({apiService.getVisitByStatus(status)},{getVisit.postValue(it)})
    }

    fun getVisitById(id: Int) {
        httpRequest({apiService.getVisitById(id)},{getVisitById.postValue(it)})
    }

    fun approveVisit(id: Int) {
        httpRequest({apiService.approveVisit(id)},{approveVisit.postValue(it)})
    }

    fun rejectVisit(id: Int) {
        httpRequest({apiService.rejectVisit(id)},{rejectVisit.postValue(it)})
    }

    fun deleteVisit(id: Int) {
        httpRequest({apiService.deleteVisit(id)},{deleteVisit.postValue(it)})
    }

    fun addVisit(bean: VisitBeanItem) {
        httpRequest({apiService.addVisit(toBody(bean))},{addVisit.postValue(it)})
    }
}